package daily.kou2022_0104;

public class NumOffer22 {
//
// 剑指 Offer 22. 链表中倒数第k个节点
public ListNode getKthFromEnd(ListNode head, int k) {
    ListNode slow = head, fast = head;
    //快指针先走k步
    while (k!=0){
        fast=fast.next;
        k--;
    }
    //同时走
    while (fast!=null){
        fast=fast.next;
        slow=slow.next;
    }
    return slow;
}
}
